home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
clean
/
sun3.lha
/
Sun3
/
system.abc
< prev
Wrap
Text File
|
1992-08-07
|
8KB
|
449 lines
| The system environment (for version numbers 0.80 etc)
|
.comp 800 111111111
.code 190 16 45
.start _no_start
.endinfo
.export EMPTY INT BOOL CHAR STRING REAL _ARRAY FILE
.export _Ind _ind_code
.export _Defer _defer_code
.export _Copy _copy_code _channel_code
.export _reserve
.export _hnf_reducer _nf_reducer _cont_reducer
.export _HnfReducer _NfReducer _ContReducer
.export _hnf _cycle_in_spine _type_error _driver
.export _Tuple
.export _S.1 _S.2 _S.3 _S.4 _S.5 _S.6 n_S.1 n_S.2 n_S.3 n_S.4 n_S.5 n_S.6
.export _Nil _Cons
.export e_system_AP e_system_sAP e_system_nAP
.export e_system_IF e_system_lIF e_system_sIF e_system_nIF
.export _match_error _add_arg
|| Basic Node Descriptors
.desc EMPTY _hnf _hnf 0 "EMPTY"
.desc INT _hnf _hnf 0 "INT"
.desc BOOL _hnf _hnf 0 "BOOL"
.desc CHAR _hnf _hnf 0 "CHAR"
.desc REAL _hnf _hnf 0 "REAL"
.desc STRING _hnf _hnf 0 "STRING"
.desc FILE _hnf _hnf 0 "FILE"
.desc _ARRAY _hnf _hnf 0 "_ARRAY"
|| Special Node Descriptors
.desc _Tuple _hnf _hnf 32 "_Tuple"
.desc _Select _hnf _hnf 2 "_Select"
.desc _Nil _hnf _hnf 0 "Nil"
.desc _Cons _hnf _l_cons 2 "Cons"
.desc e_system_AP e_system_nAP e_system_lAP 2 "AP"
.desc e_system_IF e_system_nIF e_system_lIF 3 "IF"
|| Reducer Descriptors
.desc _HnfReducer _hnf_reducer _hnf_reducer 0 "HnfReducer"
.desc _NfReducer _nf_reducer _nf_reducer 0 "NfReducer"
.desc _ContReducer _cont_reducer _cont_reducer 0 "ContReducer"
_match_error:
print "Run time error, rule \'"
printD
print "\' in module \'"
printD
print "\' does not match\n"
halt
_l_cons: create
push_a 2
push_args 2 2 2
fill _Cons 2 _hnf 2
update_a 0 2
pop_a 2
rtn
.desc _S.1 n_S.1 _hnf 1 "_S.1"
.n 1 _S.1
.o 1 0
n_S.1:
push_node _reserve 1
jsr_eval
get_node_arity 0
pushI 1
push_arg_b 0
jsr_eval
getWL 2
fill_a 0 2
release
pop_a 2
.d 1 0
rtn
.desc _S.2 n_S.2 _hnf 1 "_S.2"
.n 1 _S.2
.o 1 0
n_S.2:
push_node _reserve 1
jsr_eval
get_node_arity 0
pushI 2
push_arg_b 0
jsr_eval
getWL 2
fill_a 0 2
release
pop_a 2
.d 1 0
rtn
.desc _S.3 n_S.3 _hnf 1 "_S.3"
.n 1 _S.3
.o 1 0
n_S.3:
push_node _reserve 1
jsr_eval
get_node_arity 0
pushI 3
push_arg_b 0
jsr_eval
getWL 2
fill_a 0 2
release
pop_a 2
.d 1 0
rtn
.desc _S.4 n_S.4 _hnf 1 "_S.4"
.n 1 _S.4
.o 1 0
n_S.4:
push_node _reserve 1
jsr_eval
get_node_arity 0
pushI 4
push_arg_b 0
jsr_eval
getWL 2
fill_a 0 2
release
pop_a 2
.d 1 0
rtn
.desc _S.5 n_S.5 _hnf 1 "_S.5"
.n 1 _S.5
.o 1 0
n_S.5:
push_node _reserve 1
jsr_eval
get_node_arity 0
pushI 5
push_arg_b 0
jsr_eval
getWL 2
fill_a 0 2
release
pop_a 2
.d 1 0
rtn
.desc _S.6 n_S.6 _hnf 1 "_S.6"
.n 1 _S.6
.o 1 0
n_S.6:
push_node _reserve 1
jsr_eval
get_node_arity 0
pushI 6
push_arg_b 0
jsr_eval
getWL 2
fill_a 0 2
release
pop_a 2
.d 1 0
rtn
e_system_lAP:
print "Error: lazy entry of AP entered"
halt
e_system_nAP:
push_node _reserve 2
jsr_eval
jsr e_system_sAP
getWL 1
fill_a 0 1
release
pop_a 1
rtn
e_system_sAP:
get_node_arity 0
get_desc_arity 0
subI
eqI_b +1 0
jmp_false _add_arg
push_ap_entry 0
pop_b 1
rtn
_add_arg:
create
push_a 2
add_args 2 1 1
update_a 0 2
pop_a 2
pop_b 1
rtn
.o 2 0
e_system_lIF:
repl_args 2 2
.d 3 0
jmp eval_args_if
.n 3 e_system_IF
.o 1 0
e_system_nIF:
push_node _reserve 3
.d 3 0
jsr eval_args_if
.o 1 0
getWL 1
fill_a 0 1
release
pop_a 1
.d 1 0
rtn
.o 3 0
eval_args_if:
jsr_eval
pushB_a 0
pop_a 1
.o 2 1 b
e_system_sIF:
jmp_false IFelse
update_a 0 1
pop_a 1
jmp_eval
IFelse:
pop_a 1
jmp_eval
_hnf: rtn
_reserve: setwait 0
suspend
rtn
_hnf_reducer:
get_node
jmp_false _stop
|| is_reserved 0
|| jmp_true _done
jsr_eval
_done: pop_a 1
jmp _hnf_reducer
_stop: stop_reducer
_cont_reducer:
get_node
jmp_false _susp
is_reserved 0
jmp_true _done2
jsr_eval
_done2: pop_a 1
jmp _cont_reducer
_susp: suspend
jmp _cont_reducer
_cycle_in_spine:
print "Run Time Error: cycle in spine detected\n"
halt
_type_error: print "Run Time Error: type error\n"
halt
_apply_error: print "Run Time Error: apply error\n"
halt
.desc _Defer _defer_code _apply_error 1 "_Defer"
.desc _Copy _copy_code _apply_error 1 "_Copy"
.desc _Ind _ind_code _apply_error 1 "_I"
_defer_code:
push_node _reserve 1
|| set_red_id 1
|| force_cswitch
jsr_eval
getWL 1
fill_a 0 1
release
pop_a 1
rtn
_copy_code: push_node _reserve 1
jsr_eval
copy_graph 0
getWL 2
fill_a 0 2
release
pop_a 2
rtn
_channel_code:
push_node _reserve 0
send_request 0
setwait 0
suspend
rtn
_ind_code: push_node _reserve 1
jsr_eval
getWL 1
fill_a 0 1
release
pop_a 1
rtn
_driver: jsr _print
print_sc "\n"
halt
_print: pushI 0 | push the bracket count
_continue_print:
jsr_eval
eq_desc _ARRAY 0 0
jmp_true _print_array
eq_desc _Cons 2 0
jmp_true _print_list
eq_nulldesc _Tuple 0
jmp_true _print_tuple
eq_desc _Nil 0 0
jmp_true _print_nil
get_node_arity 0
eqI_b 0 0 | check if arity is zero
jmp_true _print_last
print_sc "("
print_symbol_sc 0
push_b 0 | replace the node by
push_b 0
repl_args_b | its arguments
_print_args:
print_sc " "
eqI_b 1 0 | check if last argument
jmp_true _print_last_arg
jsr _print
decI | decrease argument count
jmp _print_args
_print_last_arg:
pop_b 1 | remove argument count
incI | increment bracket count
jmp _continue_print | optimised tail recursion!
_print_last:
print_symbol_sc 0
pop_b 1 | remove arity
pop_a 1 | remove node
_print_brackets:
eqI_b 0 0 | stop printing brackets if
jmp_true _exit_brackets | bracket count is zero
print_sc ")"
decI | decrement bracket count
jmp _print_brackets
_exit_brackets:
pop_b 1 | remove bracket count
rtn
_print_array:
print_sc "["
get_arraysize 0
pushI 0
_print_array_args:
push_b 0
push_b 2
eqI
jmp_true _exit_print_array
eqI_b +0 0
jmp_true _not_first_arg
print_sc ","
_not_first_arg:
select 0 0
jsr _print
incI
jmp _print_array_args
_exit_print_array:
print_sc "]"
pop_a 1
pop_b 2
jmp _print_brackets
_print_list:
print_sc "["
_print_rest_list:
repl_args 2 2
jsr _print
jsr_eval
eq_desc _Nil 0 0
jmp_true _print_last_list
print_sc ","
jmp _print_rest_list
_print_last_list:
print_sc "]"
pop_a 1
jmp _print_brackets
_print_nil:
print_sc "[]"
pop_a 1
jmp _print_brackets
_print_tuple:
print_sc "("
get_node_arity 0
push_b 0
push_b 0
repl_args_b
_print_rest_tuple:
jsr _print
decI
eqI_b 0 0
jmp_true _exit_print_tuple
print_sc ","
jmp _print_rest_tuple
_exit_print_tuple:
pop_b 1
print_sc ")"
jmp _print_brackets
_nf_reduce:
jsr_eval
get_node_arity 0
eqI_b 0 0 | check if arity is zero
jmp_true _last1
push_b 0 | replace the node by
push_b 0
repl_args_b | its arguments
_reduce_args:
eqI_b 0 0 | check nr of args to do
jmp_true _last
jsr _nf_reduce
decI
jmp _reduce_args
_last1: pop_a 1
_last: pop_b 1
rtn
_nf_reducer:
get_node
jmp_false _nf_stop
jsr _nf_reduce
jmp _nf_reducer
_nf_stop: stop_reducer